define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'report/category/index' + location.search,
                    add_url: 'report/category/add',
                    edit_url: 'report/category/edit',
                    del_url: 'report/category/del',
					multi_url: 'report/category/multi',
                    table: 'report_category',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
				rowStyle:function(row,index){
					if(index%2 == 0)
					{
						return {css: {"background-color": "#c3ebd1"}};
					}
					else
					{
						return '';
					}
				},
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name')},
                        {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'status', title: __('Status'), searchList: {1: __('Normal'), 0: __('Hidden')}, formatter: Table.api.formatter.toggle},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
			$(document).on('click','button[type="reset"]', function(){
				var index = parent.Layer.getFrameIndex(window.name);
				parent.Layer.close(index);
			});	
			
            Controller.api.bindevent();
        },
        edit: function () {
			$(document).on('click','button[type="reset"]', function(){
				var index = parent.Layer.getFrameIndex(window.name);
				parent.Layer.close(index);
			});	
			
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
